package edu.dlnu.newbootdemo.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.dlnu.newbootdemo.dao.ClassesMapper;
import edu.dlnu.newbootdemo.pojo.Classes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :JinFeng
 * @description :
 * @create :2023/6/28
 */
@Service
public class ClassesServiceImpl implements IClassesService{
    @Autowired
    private ClassesMapper mapper;
    @Override
    public List<Classes> getClasses(int currPage) {
        // 实现分页：分页配置类
        PageHelper.startPage(currPage, 3);
        List<Classes> list = mapper.selectAll();
        // 分页器
        PageInfo<Classes> info = new PageInfo<>(list);
        return info.getList();
    }

    @Override
    public List<Classes> getAllClasses() {
        return mapper.selectAll();
    }

    @Override
    public boolean addClass(Classes cla) {
        return mapper.insert(cla) > 0;
    }

    @Override
    public boolean updateClass(Classes cla) {
        return mapper.updateByPrimaryKey(cla) > 0;
    }

    @Override
    public boolean delClass(int cno) {
        return mapper.deleteByPrimaryKey(cno) > 0;
    }
}
